package com.admin.education.dataTransferObject.userAnswerSheet.Mapper;

import com.admin.education.dataTransferObject.question.Mapper.QuestionMapper;;
import com.admin.education.dataTransferObject.templates.TemplatesTransfer;
import com.admin.education.dataTransferObject.userAnswerSheet.UserAnswerSheetTransfer;
import com.admin.education.models.Templates;
import com.admin.education.models.UserAnswerSheet;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper
public abstract class UserAnswerSheetMapper {
    @Autowired
    private  UserAnswerSheetQuestionMapper userAnswerSheetQuestionMapper;
    @Mappings({
            @Mapping(target = "questions", ignore = true)
    })
    public abstract UserAnswerSheetTransfer mapFrom(UserAnswerSheet userAnswerSheet);

    @Mappings({})
    public abstract List<UserAnswerSheetTransfer> mapFrom(List<UserAnswerSheet> userAnswerSheet);

    @AfterMapping
    public void afterMapping(UserAnswerSheet userAnswerSheet, @MappingTarget UserAnswerSheetTransfer userAnswerSheetTransfer) {
        if (null != userAnswerSheetTransfer.getQuestions()) {
            userAnswerSheetTransfer.setQuestions(userAnswerSheetQuestionMapper.mapFrom(userAnswerSheet.getUserAnswerSheetQuestions()));
        }
    }
}
